﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace DicomLibrary
{
    /// <summary>
    /// This class contains all the information of a Dicom data element of a dataset
    /// </summary>
    public class DDataElement
    {
        /// <summary>
        /// The DTag of this DDataElement
        /// The DTag is the identification of a Dicom data element
        /// Contains a GroupNumber and an ElementNumber
        /// </summary>
        public DTag Tag { get; set; }

        /// <summary>
        /// The Description of this DDataElement
        /// Retrieves the description from the DataDictionary.xml
        /// </summary>
        public string Description
        {  
            get
            {
                XDocument doc = XDocument.Load(@"DataDictionary.xml");
                var q = from c in doc.Descendants("Tag")
                        where String.Equals((string)c.Element("GroupNumber"), Tag.GroupNumber.ToString("x4"),StringComparison.OrdinalIgnoreCase) &&
                                String.Equals((string)c.Element("ElementNumber"),Tag.ElementNumber.ToString("x4"),StringComparison.OrdinalIgnoreCase)
                        select (string)c.Element("Description");
                return q.First();
            }
        }

        /// <summary>
        /// The DValueRepresentation of this DDataElement
        /// The value representation defines the type of the information in the data element.
        /// </summary>
        public DValueRepresentation ValueRepresentation { get; set; }

        /// <summary>
        /// The length of the value of the DDataElement in bytes
        /// </summary>
        public int ValueLength { get; set; }
        //Should this really be public?

        /// <summary>
        /// The value of this DDataElement
        /// Depending on the DValueRepresentation you have to check which type is used. 
        /// </summary>
        public object Value { get; set; }

        public override string ToString()
        {
            return this.Tag.ToString() + " " + this.Description;
        }
    }

}
